// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function inputTxt(obj, act){
    var str = "<%= t(:i_input_keywords)%>";
    if (obj.value == '' && act == 'set') {
        obj.value = str;
        obj.style.color = "#cccccc";
    }
    if (obj.value == str && act == 'clean') {
        obj.value = '';
        obj.style.color = "#666666";
    }
}

function showMeau(isShow){
    var apMenu = document.getElementById('submenu_01');
    if (apMenu) {
        if (isShow) {
            apMenu.style.display = '';
        }
        else {
            apMenu.style.display = 'none';
        }
    }
}

function showlink(){
    var eli = document.getElementsByTagName("li");
    for (var i = 0; i < eli.length; i++) {
        if (eli[i].className == 'active') {
            parent.frames[2].location = eli[i].children[0].href;
            parent.document.getElementById('frame-body').cols = '180,*';
            break;
        }
    }
}

function showMenuScrollBar(){
    var menuBoxHeight = parent.document.getElementById('menu-frame').offsetHeight;
    var heightMenuHeight = document.getElementById('heightmenu').offsetHeight;
    document.getElementById('menuoption').style.visibility = heightMenuHeight > menuBoxHeight ? 'visible' : 'hidden';
}

function menuScroll(direction){
    var menuBoxHeight = parent.document.getElementById('menu-frame').offsetHeight;
    var leftmenu = document.getElementById('leftmenu');
    var leftMenuHeight = document.getElementById('leftmenu').offsetHeight;
    var leftmenuTop = leftmenu.offsetTop;
    var stepLen = 20;
    
    if (direction == 'up') {
        if (leftmenuTop < 0) {
            leftmenu.style.marginTop = (Math.abs(leftmenuTop) < stepLen ? 0 : leftmenuTop + stepLen) + 'px';
        }
    }
    else 
        if (direction = 'down') {
            var subtraction = leftMenuHeight - menuBoxHeight;
            if (subtraction > 0) {
                leftmenu.style.marginTop = leftmenuTop - stepLen + 'px';
            }
            if (subtraction - Math.abs(leftmenuTop) < stepLen) {
                leftmenu.style.marginTop = '-' + subtraction + 'px';
            }
        }
        else {
            return;
        }
}

/*document.getElementById('separator').onclick = function(){
 if (document.body.className == 'folden') {
 document.body.className = '';
 parent.document.getElementById('frame-body').cols = '180,*';
 this.style.background = 'url(/images/admin/arrow.gif) no-repeat 0px 0px #E7E7E7';
 }
 else {
 document.body.className = 'folden';
 parent.document.getElementById('frame-body').cols = '50,*';
 this.style.background = 'url(/images/admin/arrow.gif) no-repeat -139px -28px';
 }
 }*/
function changeMenu(obj) {
    var tagList = obj.parentNode;
    var tagOptions = tagList.getElementsByTagName("li");
    var tagOptionsLen = tagOptions.length;
    for (i = 1; i < tagOptionsLen; i++) {
        if (tagOptions[i].className.indexOf('active') >= 0) {
            tagOptions[i].className = '';
        }
    }
    obj.className = 'active';
}

function tabSwitch(changeTitle) {
    if (changeTitle == undefined) {
        changeTitle = true;
    }
    var tc = $$(".tabContent > .tabConBody");
    var tab = $$(".tab_nav > ul > li");
    for (var t = 1; t <= tc.length; t++) {
        document.getElementById('tab' + t).onclick = function(){
            for (var i = 0; i < tc.length; i++) {
                tc[i].style.display = 'none';
                tab[i].className = '';
            }
            var arr = this.id.split('');
            document.getElementById('tc' + arr[arr.length - 1]).style.display = 'block';
            this.className = 'on';
            if (changeTitle) {
                document.title = this.getElementsByTagName('label')[0].innerHTML;
            }
            return false;
        }
    }
}
